local L = LibStub("AceLocale-3.0"):GetLocale("RaidFramesPlus", true)
local setupPanel
local setupPanel2

StaticPopupDialogs["NewAura"] = {
  text = L["Add the following Aura to the list"],
  button1 = L["Okay"],
  button2 = L["Cancel"],
  OnShow = function()
	_G[this:GetName().."EditBox"]:SetText("")
  end,
  OnAccept = function()
      RaidFramesPlus_DebuffColorList[getglobal(this:GetParent():GetName().."EditBox"):GetText()] = { 1, 1, 1, 1}
	  RaidFramesPlus_PopulateDebuffList(scrollFrame)
  end,
  timeout = 0,
  whileDead = 1,
  hideOnEscape = 1,
  hasEditBox = 1
}

function RaidFramesPlus_PopulateDebuffList(scrollFrame)
local childrenList = {scrollFrame:GetChildren()}
	for i,child in pairs(childrenList) do
		child:Hide()
	end
local childrenList = {scrollFrame:GetRegions()}
	for i,child in pairs(childrenList) do
		child:Hide()
	end
local i = 0
	for auraname, color in pairs(RaidFramesPlus_DebuffColorList) do
		if color then
			local colorSwatch = _G["colorSwatch_"..auraname] or CreateFrame("Button", "colorSwatch_"..auraname, scrollFrame, "ChatConfigSwatchTemplate")
			colorSwatch:Show()
			_G["colorSwatch_"..auraname.."Text"]:SetText(auraname)
			if i == 0 then
				colorSwatch:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 8, -6)
			else
				colorSwatch:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 8, i * -(colorSwatch:GetHeight()))
			end

			_G["colorSwatch_"..auraname.."ColorSwatch"]:GetNormalTexture():SetVertexColor(unpack(color))
			_G["colorSwatch_"..auraname.."ColorSwatch"].id = auraname
			_G["colorSwatch_"..auraname.."ColorSwatch"]:SetScript("OnClick", function(self, button)

				local function getColor()
					local r,g,b = ColorPickerFrame:GetColorRGB()
					RaidFramesPlus_DebuffColorList[self.id] = {r,g,b,1}
					_G["colorSwatch_"..auraname.."ColorSwatch"]:GetNormalTexture():SetVertexColor(r,g,b,1)
				end
				ColorPickerFrame.func = getColor

				local pr, pg, pb
				pr,pg,pb = _G[self:GetName().."NormalTexture"]:GetVertexColor()
				ColorPickerFrame.previousValues = {pr,pg,pb}
				ColorPickerFrame:SetColorRGB(pr, pg, pb)

				ColorPickerFrame:Show()
			end)

			local btn = CreateFrame("Button", "removeColorSwatch"..auraname, scrollFrame)
			btn:SetWidth(16)
			btn:SetHeight(16)
			btn:SetDisabledTexture("interface\\buttons\\ui-minusbutton-disabled")
			btn:SetPushedTexture("interface\\buttons\\ui-minusbutton-down")
			btn:SetHighlightTexture("interface\\buttons\\ui-plusbutton-hilight")
			btn:SetNormalTexture("interface\\buttons\\ui-minusbutton-up")
			btn:SetPoint("LEFT", colorSwatch, "RIGHT", 0,0)
			i = i + 1
			btn.id = auraname
			btn:SetScript("OnClick", function(self)
				RaidFramesPlus_DebuffColorList[auraname] = nil
				RaidFramesPlus_PopulateDebuffList(self:GetParent())
			end)
			scrollFrame:SetHeight(i * (6 + colorSwatch:GetHeight()))
		end
	end
end

--- this function creates a graphical configuration interface
function RaidFramesPlus_CreateOptionPanel()
	setupPanel = CreateFrame("FRAME", "RaidFramesPlus_SetupPanel")
	setupPanel.name = L["RaidFramesPlus"]
	InterfaceOptions_AddCategory(setupPanel)

	setupPanel2 = CreateFrame("FRAME", "RaidFramesPlus_SetupPanel2")
	setupPanel2.name = L["Debuffs"]
	setupPanel2.parent = L["RaidFramesPlus"]
	InterfaceOptions_AddCategory(setupPanel2)
	RaidFramesPlus_CreateOptionPanel2()

	-- the actual interface option panel will be initialized not before the optionpanel is called
	setupPanel:SetScript("OnShow", function(setupPanel)
		setupPanel:SetScript("OnShow", nil)

		-- the title of this Configurationpanel
		local title = setupPanel:CreateFontString("RaidFramesPlus_Title")
		title:SetPoint("TOPLEFT", 16, -16)
		title:SetFontObject(GameFontNormalLarge)
		title:SetText(L["RaidFramesPlus"])

		-- descriptiontext to explain those configuration elements (for what they are and further advices)
		local descriptionText = setupPanel:CreateFontString("RaidFramesPlus_DescriptionText")
		descriptionText:SetFontObject(GameFontHighlightSmall)
		descriptionText:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
		descriptionText:SetPoint("RIGHT", -30, 0)
		descriptionText:SetHeight(32)
		descriptionText:SetJustifyH("LEFT")
		descriptionText:SetJustifyV("TOP")
		descriptionText:SetText(L["Customize the RaidFrames to your needs, see also Game-properties > Unitframes to customize buff/debuff display on RaidFrames "])

		-- version of this addon
		local version = setupPanel:CreateFontString("RaidFramesPlus_Version")
		version:SetPoint("BOTTOMRIGHT", -16, 16)
		version:SetFontObject(GameFontNormalSmall)
		version:SetText(L["|cFF888888 version "]..GetAddOnMetadata("RaidFramesPlus", "Version").."|r")

		-- create a checkbutton for the SavedVariable RaidFramesPlus_ShowRaidTargetIcons
		local raidTargetIconCheckButton = CreateFrame("CheckButton", "RaidFramesPlus_RaidTargetIconCheckButton", setupPanel, "OptionsCheckButtonTemplate")
		RaidFramesPlus_RaidTargetIconCheckButtonText:SetText(L["|cFFFFFFFFRaidtarget Icons|r"])
		raidTargetIconCheckButton:SetPoint("TOPLEFT", descriptionText, "BOTTOMLEFT", 0, -8)
		raidTargetIconCheckButton:SetChecked(RaidFramesPlus_ShowRaidTargetIcons)

		-- create a checkbutton for the SavedVariable RaidFramesPlus_CompactPullouts
		local compactCheckButton = CreateFrame("CheckButton", "RaidFramesPlus_CompactCheckButton", setupPanel, "OptionsCheckButtonTemplate")
		RaidFramesPlus_CompactCheckButtonText:SetText(L["|cFFFFFFFFCompact Display|r"])
		compactCheckButton:SetPoint("TOPLEFT",raidTargetIconCheckButton, "BOTTOMLEFT", 0, -8)
		compactCheckButton:SetChecked(RaidFramesPlus_CompactPullouts)

		-- create a slider for the SavedVariable RaidFramesPlus_Scale
		local scaleSlider = CreateFrame("Slider", "RaidFramesPlus_ScaleSlider", setupPanel, "OptionsSliderTemplate")
		scaleSlider:SetMinMaxValues(0.5, 2.0)
		scaleSlider:SetValue(RaidFramesPlus_Scale)
		RaidFramesPlus_ScaleSliderText:SetFormattedText(L["Scalefactor: %.2d%%"], RaidFramesPlus_Scale * 100)
		RaidFramesPlus_ScaleSliderLow:SetText("50%")
		RaidFramesPlus_ScaleSliderHigh:SetText("200%")
		scaleSlider:SetScript("OnValueChanged", function(self)
			RaidFramesPlus_ScaleSliderText:SetFormattedText(L["Scalefactor: %d%%"], self:GetValue() * 100)
		end)
		scaleSlider:SetPoint("RIGHT", descriptionText)
		scaleSlider:SetPoint("BOTTOM", raidTargetIconCheckButton)

		-- create a checkbutton for the SavedVariable RaidFramesPlus_IsVerticalLayout
		local horizontalCheckButton = CreateFrame("CheckButton", "RaidFramesPlus_HorizontalCheckButton", setupPanel, "OptionsCheckButtonTemplate")
		RaidFramesPlus_HorizontalCheckButtonText:SetText(L["|cFFFFFFFFArrange Frames horizontal|r"])
		horizontalCheckButton:SetChecked(RaidFramesPlus_IsVerticalLayout)
		horizontalCheckButton:SetPoint("TOPLEFT", compactCheckButton, "BOTTOMLEFT", 0, -8)

		-- create a Checkbutton that enables if Checked the radiobutton-group for the SavedVariable RaidFramesPlus_Health
		local healthText0CheckButton = CreateFrame("CheckButton", "RaidFramesPlus_HealthText0CheckButton", setupPanel, "OptionsCheckButtonTemplate")
		RaidFramesPlus_HealthText0CheckButtonText:SetText(L["|cFFFFFFFFDisplay Healthvalues in |r"])
		healthText0CheckButton:SetChecked(not(RaidFramesPlus_Health == 0))
		healthText0CheckButton:SetScript("OnClick", function(self)
			if self:GetChecked() then
				RaidFramesPlus_HealthText1CheckButton:Enable()
				RaidFramesPlus_HealthText2CheckButton:Enable()
				RaidFramesPlus_HealthText3CheckButton:Enable()
				RaidFramesPlus_HealthText4CheckButton:Enable()
				RaidFramesPlus_HealthText5CheckButton:Enable()
			else
				RaidFramesPlus_HealthText1CheckButton:Disable()
				RaidFramesPlus_HealthText2CheckButton:Disable()
				RaidFramesPlus_HealthText3CheckButton:Disable()
				RaidFramesPlus_HealthText4CheckButton:Disable()
				RaidFramesPlus_HealthText5CheckButton:Disable()
			end
		end)
		healthText0CheckButton:SetPoint("TOPLEFT", horizontalCheckButton, "BOTTOMLEFT", 0, -8)

		local alphaSlider = CreateFrame("Slider", "RaidFramesPlus_AlphaSlider", setupPanel, "OptionsSliderTemplate")
		alphaSlider:SetMinMaxValues(0, 1.0)
		alphaSlider:SetValue(RaidFramesPlus_Alpha)
		RaidFramesPlus_AlphaSliderText:SetFormattedText(L["Alphafactor: %d%%"], RaidFramesPlus_Alpha*100)
		RaidFramesPlus_AlphaSliderLow:SetText("0%")
		RaidFramesPlus_AlphaSliderHigh:SetText("100%")
		alphaSlider:SetPoint("RIGHT", descriptionText)
		alphaSlider:SetPoint("BOTTOM",horizontalCheckButton)
		alphaSlider:SetScript("OnValueChanged", function(self)
			RaidFramesPlus_AlphaSliderText:SetFormattedText(L["Alphafactor: %d%%"], self:GetValue()*100)
		end)

		local healthBarText = setupPanel:CreateFontString()
		healthBarText:SetFontObject("GameFontNormal")
		healthBarText:SetText(L["Doublesize Healthbar"])
		healthBarText:SetPoint("LEFT", alphaSlider)
		healthBarText:SetPoint("BOTTOM", healthText0CheckButton)
		local healthBarComboBox = CreateFrame("Frame", "RaidFramesPlus_HealthBarComboBox", setupPanel, "UIDropDownMenuTemplate");
		healthBarComboBox:SetPoint("TOPLEFT", healthBarText, "BOTTOMLEFT",-10,-10)
		UIDropDownMenu_SetWidth(RaidFramesPlus_HealthBarComboBox, 120)
		function RaidFramesPlus_HealthBarComboBox_Initialise()
			level = 1
			local info = UIDropDownMenu_CreateInfo()
			info.text = L["Allways"]
			info.value = 2
			info.func = function(self)
				UIDropDownMenu_SetText(RaidFramesPlus_HealthBarComboBox, "Allways")
				RaidFramesPlus_HealthBarComboBox.value = this.value
				self.checked = true
			end
			info.owner = this:GetParent()
			info.checked = (RaidFramesPlus_HealthBarComboBox.value == 2)
			info.icon = nil
			UIDropDownMenu_AddButton(info, level)

			local info = UIDropDownMenu_CreateInfo()
			info.text = L["No Mana"]
			info.value = 1
			info.func = function(self)
				RaidFramesPlus_HealthBarComboBox.value = this.value
				self.checked = true
				UIDropDownMenu_SetText(RaidFramesPlus_HealthBarComboBox, "No Mana")
			end
			info.owner = this:GetParent()
			info.checked = (RaidFramesPlus_HealthBarComboBox.value == 1)
			info.icon = nil
			UIDropDownMenu_AddButton(info, level)

			local info = UIDropDownMenu_CreateInfo()
			info.text = L["Never"]
			info.value = -1
			info.func = function(self)
				RaidFramesPlus_HealthBarComboBox.value = this.value
				self.checked = true
				UIDropDownMenu_SetText(RaidFramesPlus_HealthBarComboBox, "Never")
			end
			info.owner = this:GetParent()
			info.checked = (RaidFramesPlus_HealthBarComboBox.value == -1)
			info.icon = nil
			UIDropDownMenu_AddButton(info, level)
		end
		UIDropDownMenu_Initialize(RaidFramesPlus_HealthBarComboBox, RaidFramesPlus_HealthBarComboBox_Initialise)

		-- change the text of this dropdownbutton to reflect the SavedVariable
		if RaidFramesPlus_HealthBarSize == 2 then
			UIDropDownMenu_SetText(RaidFramesPlus_HealthBarComboBox, L["Allways"])
		elseif RaidFramesPlus_HealthBarSize == 1 then
			UIDropDownMenu_SetText(RaidFramesPlus_HealthBarComboBox, L["No Mana"])
		else
			UIDropDownMenu_SetText(RaidFramesPlus_HealthBarComboBox, L["Never"])
		end

		local healthText1CheckButton = CreateFrame("CheckButton", "RaidFramesPlus_HealthText1CheckButton", setupPanel, "OptionsSmallCheckButtonTemplate")
		RaidFramesPlus_HealthText1CheckButtonText:SetText(L["Absolute Values"])
		healthText1CheckButton:SetChecked(RaidFramesPlus_Health == 1)
		healthText1CheckButton:SetScript("OnClick", function(self)
			-- radiobutton-group behavior if this one is checked uncheck the other buttons
			if self:GetChecked() then
				RaidFramesPlus_HealthText2CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText3CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText4CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText5CheckButton:SetChecked(false)
			end
			-- you can only check this one by clicking on it
			RaidFramesPlus_HealthText1CheckButton:SetChecked(true)
		end)
		healthText1CheckButton:SetPoint("TOPLEFT", healthText0CheckButton, "BOTTOMLEFT", 8, -8)

		local healthText2CheckButton = CreateFrame("CheckButton", "RaidFramesPlus_HealthText2CheckButton", setupPanel, "OptionsSmallCheckButtonTemplate")
		RaidFramesPlus_HealthText2CheckButtonText:SetText(L["Percent"])
		healthText2CheckButton:SetChecked(RaidFramesPlus_Health == 2)
		healthText2CheckButton:SetScript("OnClick", function(self)
			if self:GetChecked() then
				RaidFramesPlus_HealthText1CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText3CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText4CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText5CheckButton:SetChecked(false)
			end
			RaidFramesPlus_HealthText2CheckButton:SetChecked(true)
		end)
		healthText2CheckButton:SetPoint("TOPLEFT", healthText1CheckButton, "BOTTOMLEFT", 0, -8)

		local healthText3CheckButton = CreateFrame("CheckButton", "RaidFramesPlus_HealthText3CheckButton", setupPanel, "OptionsSmallCheckButtonTemplate")
		RaidFramesPlus_HealthText3CheckButtonText:SetText(L["K-Values"])
		healthText3CheckButton:SetChecked(RaidFramesPlus_Health == 3)
		healthText3CheckButton:SetScript("OnClick", function(self)
			if self:GetChecked() then
				RaidFramesPlus_HealthText1CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText2CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText4CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText5CheckButton:SetChecked(false)
			end
			RaidFramesPlus_HealthText3CheckButton:SetChecked(true)
		end)
		healthText3CheckButton:SetPoint("TOPLEFT", healthText2CheckButton, "BOTTOMLEFT", 0, -8)

		local healthText4CheckButton = CreateFrame("CheckButton", "RaidFramesPlus_HealthText4CheckButton", setupPanel, "OptionsSmallCheckButtonTemplate")
		RaidFramesPlus_HealthText4CheckButtonText:SetText(L["Deficite"])
		healthText4CheckButton:SetChecked(RaidFramesPlus_Health == 4)
		healthText4CheckButton:SetScript("OnClick", function(self)
			if self:GetChecked() then
				RaidFramesPlus_HealthText1CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText2CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText3CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText5CheckButton:SetChecked(false)
			end
			RaidFramesPlus_HealthText4CheckButton:SetChecked(true)
		end)

		healthText4CheckButton:SetPoint("TOPLEFT", healthText3CheckButton, "BOTTOMLEFT", 0, -8)

		local healthText5CheckButton = CreateFrame("CheckButton", "RaidFramesPlus_HealthText5CheckButton", setupPanel, "OptionsSmallCheckButtonTemplate")
		healthText5CheckButton:SetChecked(RaidFramesPlus_Health == 5)
		RaidFramesPlus_HealthText5CheckButtonText:SetText(L["Custom Format"])
		healthText5CheckButton:SetScript("OnClick", function(self)
			if self:GetChecked() then
				RaidFramesPlus_HealthText1CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText2CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText3CheckButton:SetChecked(false)
				RaidFramesPlus_HealthText4CheckButton:SetChecked(false)
			end
			RaidFramesPlus_HealthText5CheckButton:SetChecked(true)
		end)

		healthText5CheckButton:SetPoint("TOPLEFT", healthText4CheckButton, "BOTTOMLEFT", 0, -8)

		local healthTextCustomEditBox = CreateFrame("EditBox", "RaidFramesPlus_HealthTextCustomEditBox", setupPanel, "InputBoxTemplate")
		healthTextCustomEditBox:SetText((RaidFramesPlus_CustomFormat or ""))
		healthTextCustomEditBox:SetPoint("TOPLEFT", healthText5CheckButton, "BOTTOMLEFT", 16, -8)
		healthTextCustomEditBox:SetWidth(128)
		healthTextCustomEditBox:SetHeight(24)

		healthTextCustomEditBox:SetScript("OnEnter", function(self)
			-- create a Gametooltip that explains how the Editbox works
			GameTooltip:ClearLines()
			GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
			GameTooltip:AddLine(L["Use the following tokens to customize the health string"])
			GameTooltip:AddDoubleLine("$abs", L["Current Health in absolute value"], 1,1,1)
			GameTooltip:AddDoubleLine("$max", L["Maximum Health in absolute value"], 1,1,1)
			GameTooltip:AddDoubleLine("$dif", L["Deficite Health in absolute value"], 1,1,1)
			GameTooltip:AddDoubleLine("$abk", L["Current Health in thousands (k)"], 1,1,1)
			GameTooltip:AddDoubleLine("$mak", L["Maximum Health in thousands (k)"], 1,1,1)
			GameTooltip:AddDoubleLine("$difk", L["Deficite Health in thousands (k)"], 1,1,1)
			GameTooltip:Show()
		end)
		healthTextCustomEditBox:SetScript("OnLeave", function()
			GameTooltip:ClearLines()
			GameTooltip:Hide()
		end)
		healthTextCustomEditBox:SetScript("OnEnterPressed", function(self)
			self:ClearFocus()
		end)
		healthTextCustomEditBox:SetAutoFocus(false)
		healthTextCustomEditBox:ClearFocus()

		setupPanel.default = function()
			-- defaultvalues
			RaidFramesPlus_Health = 1
			RaidFramesPlus_CompactPullouts = 1
			RaidFramesPlus_Scale = 1
			RaidFramesPlus_Alpha = 0.75
			RaidFramesPlus_IsVerticalLayout = nil
			RaidFramesPlus_HealthBarSize = 1

			-- reflect these defaultvalues in the option controls
			RaidFramesPlus_CompactCheckButton:SetChecked(1)
			RaidFramesPlus_HorizontalCheckButton:SetChecked(nil)
			RaidFramesPlus_HealthText0CheckButton:SetChecked(1)
			RaidFramesPlus_HealthText1CheckButton:SetChecked(1)
			RaidFramesPlus_HealthText2CheckButton:SetChecked(nil)
			RaidFramesPlus_HealthText3CheckButton:SetChecked(nil)
			RaidFramesPlus_HealthText4CheckButton:SetChecked(nil)
			RaidFramesPlus_HealthText5CheckButton:SetChecked(nil)
			RaidFramesPlus_RaidTargetIconCheckButton:SetChecked(1)
			RaidFramesPlus_ScaleSlider:SetValue(1)
			RaidFramesPlus_AlphaSlider:SetValue(0.75)

			-- and also update the raidframes to reflect the 'new' default settings
			RaidFramesPlus_Update("Health", RaidFramesPlus_UnitThreatSituationUpdate)
			RaidFramesPlus_Update("Health", RaidFramesPlus_UnitHealth)
			RaidFramesPlus_Update("RaidTargetIcon", RaidFramesPlus_RaidTargetUpdate)
			RaidFramesPlus_Update("", RaidFramesPlus_ScaleButton)
			RaidFramesPlus_LayoutManager()
			RaidFramesPlus_RaidRosterUpdate()

		end

		setupPanel.cancel = function()
			-- revert all SetChecked states from the SavedVariables
			RaidFramesPlus_CompactCheckButton:SetChecked(RaidFramesPlus_CompactPullouts)
			RaidFramesPlus_RaidTargetIconCheckButton:SetChecked(RaidFramesPlus_ShowRaidTargetIcons)
			RaidFramesPlus_HorizontalCheckButton(RaidFramesPlus_IsVerticalLayout)

			-- because the Checkbuttons below are actually radiobuttons the
			-- SavedVariable is checked against thier values
			RaidFramesPlus_HealthText0CheckButton:SetChecked(RaidFramesPlus_Health > 0)
			RaidFramesPlus_HealthText1CheckButton:SetChecked(RaidFramesPlus_Health == 1)
			RaidFramesPlus_HealthText2CheckButton:SetChecked(RaidFramesPlus_Health == 2)
			RaidFramesPlus_HealthText3CheckButton:SetChecked(RaidFramesPlus_Health == 3)
			RaidFramesPlus_HealthText4CheckButton:SetChecked(RaidFramesPlus_Health == 4)
			RaidFramesPlus_HealthText5CheckButton:SetChecked(RaidFramesPlus_Health == 5)
			RaidFramesPlus_HealthTextCustomEditBox:SetEnabled(RaidFramesPlus_Health == 5)

			-- revert the slider values from the SavedVariables
			RaidFramesPlus_ScaleSlider:SetValue(RaidFramesPlus_Scale)
			RaidFramesPlus_AlphaSlider:SetValue(RaidFramesPlus_Alpha)
		end

		setupPanel.okay = function()
			-- get 1nil values of the checkbuttons to store them in SavedVariables
			RaidFramesPlus_CompactPullouts = RaidFramesPlus_CompactCheckButton:GetChecked()
			RaidFramesPlus_ShowRaidTargetIcons = RaidFramesPlus_RaidTargetIconCheckButton:GetChecked()
			RaidFramesPlus_IsVerticalLayout = RaidFramesPlus_HorizontalCheckButton:GetChecked()

			-- get number values of the sliders to also store them in SavedVariables
			RaidFramesPlus_Scale = RaidFramesPlus_ScaleSlider:GetValue()
			RaidFramesPlus_Alpha = RaidFramesPlus_AlphaSlider:GetValue()

			-- get the Dropdownvalue and store it
			RaidFramesPlus_HealthBarSize = RaidFramesPlus_HealthBarComboBox.value

			-- only one option can apply how the healthtext should be formatted
			if not RaidFramesPlus_HealthText0CheckButton:GetChecked() then
				RaidFramesPlus_Health = 0
			elseif RaidFramesPlus_HealthText1CheckButton:GetChecked() then
				RaidFramesPlus_Health = 1
			elseif RaidFramesPlus_HealthText2CheckButton:GetChecked() then
				RaidFramesPlus_Health = 2
			elseif RaidFramesPlus_HealthText3CheckButton:GetChecked() then
				RaidFramesPlus_Health = 3
			elseif RaidFramesPlus_HealthText4CheckButton:GetChecked() then
				RaidFramesPlus_Health = 4
			elseif RaidFramesPlus_HealthText5CheckButton:GetChecked() then
				RaidFramesPlus_Health = 5
				RaidFramesPlus_CustomFormat = RaidFramesPlus_HealthTextCustomEditBox:GetText()
			end

			-- update the raidframes to reflect the new settings
			RaidFramesPlus_Update("Health", RaidFramesPlus_UnitThreatSituationUpdate)
			RaidFramesPlus_Update("Health", RaidFramesPlus_UnitHealth)
			RaidFramesPlus_Update("", RaidFramesPlus_DoubleHealthBar)
			RaidFramesPlus_Update("RaidTargetIcon", RaidFramesPlus_RaidTargetUpdate)
			RaidFramesPlus_Update("", RaidFramesPlus_ScaleButton)
			RaidFramesPlus_LayoutManager()
			RaidFramesPlus_RaidRosterUpdate()
		end


		end)
end

function RaidFramesPlus_CreateOptionPanel2()
	local setupPanel = setupPanel2

	-- the actual interface option panel will be initialized not before the optionpanel is called
	setupPanel2:SetScript("OnShow", function(setupPanel)
		setupPanel2:SetScript("OnShow", nil)

		-- the title of this Configurationpanel
		local title = setupPanel:CreateFontString("RaidFramesPlus_Title2")
		title:SetPoint("TOPLEFT", 16, -16)
		title:SetFontObject(GameFontNormalLarge)
		title:SetText(L["Debuff settings"])

		-- descriptiontext to explain those configuration elements (for what they are and further advices)
		local descriptionText = setupPanel:CreateFontString("RaidFramesPlus_DescriptionText2")
		descriptionText:SetFontObject(GameFontHighlightSmall)
		descriptionText:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
		descriptionText:SetPoint("RIGHT", -30, 0)
		descriptionText:SetHeight(32)
		descriptionText:SetJustifyH("LEFT")
		descriptionText:SetJustifyV("TOP")
		descriptionText:SetText(L["Change the way debuffs and buffs are displayed and create custom debuff/buff highlightning."])

		local customBuffs = CreateFrame("CheckButton", "RaidFramesPlus_CustomBuffs", setupPanel, "OptionsCheckButtonTemplate")
		RaidFramesPlus_CustomBuffsText:SetText(L["|cFFFFFFFFDisplay the following Auras first|r"])
		customBuffs:SetPoint("TOPLEFT", descriptionText, "BOTTOMLEFT", 0, -8)

		local scroll = CreateFrame("ScrollFrame", "RaidFramesPlus_CustomBuffs_ScrollFrame", setupPanel, "UIPanelScrollFrameTemplate")
		scroll:SetPoint("TOPLEFT", customBuffs, "BOTTOMLEFT", 20, -20)
		scroll:SetPoint("RIGHT", setupPanel, -140, 0)
		scroll:SetPoint("BOTTOM", setupPanel, 0, 20)
		scroll:SetBackdrop({bgFile = nil,
                                            edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                                            tile = true, tileSize = 16, edgeSize = 16,
                                            insets = { left = 4, right = 4, top = 4, bottom = 4 }})
		local scrollAdd = CreateFrame("Button", "RaidFramesPlus_CustomBuffs_ScrollFrame_Add", setupPanel, "UIPanelButtonTemplate")
		scrollAdd:SetText(L["Add Aura"])

		scrollAdd:SetPoint("TOPLEFT", scroll, "TOPRIGHT", 30, 0)
		scrollAdd:SetHeight(20)
		scrollAdd:SetWidth(100)

		scrollAdd:SetScript("OnClick", function(self)
			StaticPopup_Show ("NewAura")
		end)

		scrollFrame = CreateFrame("Frame", "RaidFramesPlus_CustomBuffs_ScrollChildFrame", scroll)
		scrollFrame:SetPoint("TOPLEFT", scroll)
		scrollFrame:SetWidth(400)
		scrollFrame:SetHeight(800)
		RaidFramesPlus_PopulateDebuffList(scrollFrame)
		scroll:SetScrollChild(scrollFrame)

		setupPanel.okay = function()
			RaidFramesPlus_DebuffColorListEnabled = RaidFramesPlus_CustomBuffs:GetChecked()
		end
		setupPanel.default = function()
			RaidFramesPlus_DebuffColorListEnabled = 1

		end
		setupPanel.cancel = function()

		end
	end)
end

